<template>
  <div>
    <div class="item-line">
      <div>输入变量</div>
      <div>
        <ac-select
          v-model="data.sourceParamId"
          :options="sourceParamOptions"
        />
      </div>
    </div>
    <div class="item-line">
      <div class="inline">
        <div style="flex-grow: 1">知识库</div>
        <knowledge-select v-model="data.knowledgeList" />
      </div>
      <div class="knowledge-box">
        <div
          v-for="(knowledge, index) in data.knowledgeList"
          :key="index"
          class="knowledge-item"
        >
          <div :title="knowledge.name">{{knowledge.name}}</div>
          <ac-icon
            size="14"
            color="red"
            iconId="018dc9c3efd3a0502886"
            title="删除"
            @click.stop="deleteKnowledge(index)"
          />
        </div>
      </div>
    </div>
    <div class="item-line">
      <div>输出变量</div>
      <div
        v-for="(item, index) in data.outputList"
        :key="index"
        style="color: #666"
      >
        <div>{{'<' + item.type + '>' }} {{item.name}}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import KnowledgeSelect from "@/admin/ai/components/knowledge-select.vue";

const props = defineProps({
  data: {
    type: Object,
    default: () => {
      return {
        inputList: [],
        outputList: [],
        knowledgeList: []
      }
    }
  },
  sourceParamOptions: {
    type: Object,
    default: () => {}
  }
});

const data = ref(props.data);

const deleteKnowledge = (index) => {
  data.value.knowledgeList.splice(index, 1);
};
</script>

<style scoped>
.item-line {
  margin-top: 15px;
  >div:first-child {
    margin-bottom: 5px;
  }
}
.button-box {
  margin-top: 10px;
  display: flex;
  align-items: center;
  .button {
    color: #67C23A;
    cursor: pointer;
    display: flex;
    align-items: center;
    .ac-icon {
      margin-right: 8px;
    }
  }
}
.inline {
  display: flex;
}
.classifier-item {
  margin-top: 10px;
  position: relative;
  .classifier-header {
    box-sizing: border-box;
    padding: 5px;
    position: absolute;
    width: 100%;
    display: flex;
    color: #bbbbbb;
    div:first-child {
      flex-grow: 1;
    }
    .ac-icon {
      z-index: 99;
      cursor: pointer;
    }
  }
  :deep(textarea) {
    padding-top: 28px;
    background-color: transparent;
  }
}
.knowledge-box {
  display: flex;
  box-sizing: border-box;
  flex-wrap: wrap;
  gap: 10px;
  .knowledge-item {
    width: calc(50% - 32px);
    border: 1px solid #d5d6d9;
    border-radius: 4px;
    padding: 8px 12px;
    display: flex;
    flex-direction: row;
    div:first-child {
      flex-grow: 1;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .ac-icon {
      cursor: pointer;
      flex-shrink: 0;
    }
  }
}
</style>